package com.ruoyi.fantasy.service.impl;

import java.util.List;
import java.util.Map;

import com.huanzhidadi.fantasy.bean.domain.FantasyCity;
import com.ruoyi.fantasy.common.WorldInit;
import com.ruoyi.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.fantasy.mapper.FantasyCitiesMapper;
import com.ruoyi.fantasy.service.IFantasyCitiesService;
import com.ruoyi.common.core.text.Convert;

/**
 * 城市 服务层实现
 * 
 * @author ruoyi
 * @date 2018-12-05
 */
@Service
public class FantasyCitiesServiceImpl implements IFantasyCitiesService 
{
	@Autowired
	private FantasyCitiesMapper fantasyCitiesMapper;

	/**
     * 查询城市信息
     * 
     * @param id 城市ID
     * @return 城市信息
     */
    @Override
	public FantasyCity selectFantasyCitiesById(Integer id)
	{
	    return fantasyCitiesMapper.selectFantasyCitiesById(id);
	}
	
	/**
     * 查询城市列表
     * 
     * @param fantasyCities 城市信息
     * @return 城市集合
     */
	@Override
	public List<FantasyCity> selectFantasyCitiesList(FantasyCity fantasyCities)
	{
	    return fantasyCitiesMapper.selectFantasyCitiesList(fantasyCities);
	}
	
    /**
     * 新增城市
     * 
     * @param fantasyCities 城市信息
     * @return 结果
     */
	@Override
	public int insertFantasyCities(FantasyCity fantasyCities)
	{
	    return fantasyCitiesMapper.insertFantasyCities(fantasyCities);
	}
	
	/**
     * 修改城市
     * 
     * @param fantasyCities 城市信息
     * @return 结果
     */
	@Override
	public int updateFantasyCities(FantasyCity fantasyCities)
	{
	    return fantasyCitiesMapper.updateFantasyCities(fantasyCities);
	}

	/**
     * 删除城市对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteFantasyCitiesByIds(String ids)
	{
		return fantasyCitiesMapper.deleteFantasyCitiesByIds(Convert.toStrArray(ids));
	}

	/**
	 * 禁用城市对象
	 *
	 * @param ids 需要禁用的数据ID
	 * @return 结果
	 */
	@Override
	public int disableFantasyCitiesByIds(String ids)
	{
		return fantasyCitiesMapper.disableFantasyCitiesByIds(Convert.toStrArray(ids));
	}

	/**
	 * 还原城市对象
	 *
	 * @param ids 需要还原的数据ID
	 * @return 结果
	 */
	@Override
	public int restoreFantasyCitiesByIds(String ids)
	{
		return fantasyCitiesMapper.restoreFantasyCitiesByIds(Convert.toStrArray(ids));
	}

	@Override
	public void transforData(List<FantasyCity> list) {
		Map<String, SysUser> sysUserMap = WorldInit.sysUserMap;
		for (FantasyCity city : list) {
			if (city.getCreateBy() != null) {
				if (sysUserMap.get(city.getCreateBy()) != null) {
					city.setCreateBy(sysUserMap.get(city.getCreateBy()).getUserName());
				} else {
					city.setCreateBy("系统管理员");
				}
			}
			if (city.getUpdateBy() != null) {
				if (sysUserMap.get(city.getUpdateBy()) != null) {
					city.setUpdateBy((sysUserMap.get(city.getUpdateBy()).getUserName()));
				} else {
					city.setUpdateBy("系统管理员");
				}
			}
			//禁用标记
			if (city.getDelFlag().equals("0")) {
				city.setDelFlag("正常");
			} else if (city.getDelFlag().equals("1")) {
				city.setDelFlag("禁用");
			}
		}
	}

}
